package cn.zktr.Personnel.controllers.zhouyongcong.end;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.end.loginService;

@Controller
public class loginController {
	
	@Autowired
	private findService fs;
	@Autowired
	private loginService ajs;
	
	@RequestMapping("zyc/emp-login")
	public void emp_individual(Model mod) {
		mod.addAttribute("Rcd", fs.findAllRcd());
	}
	
	@RequestMapping("emp-login")
	@ResponseBody
	public boolean emp_login_ru(Integer prrid) {
		System.err.println("进来了:"+prrid);
		ajs.emp_login_ru(fs.findRcdid(prrid));
		return true;
	}
	
	@RequestMapping("emp_table")
	@ResponseBody
	public Map<String,Object> emp_table(Integer page,Integer rows) {
		Map<String,Object> map = new HashMap<>();
		JSONArray json = new JSONArray();
		map.put("total",fs.findAllEmp().size());
		int i=0;
		for(PerPmsEmp ppe : fs.findAllEmp()){
			if((page-1)*rows<=i&&i<page*rows&&ppe.getPerPmsStms().size()!=0) {
				JSONObject jo = new JSONObject();
				jo.put("empid", ppe.getEmpid());
	            jo.put("empname", ppe.getEmpname());
	            jo.put("position", ppe.getPerPmsStms().get(0).getPerPmsPot().getPotzw());
	            jo.put("sector", ppe.getPerPmsStms().get(0).getPerPmsDept().getDeptname());
	            if(ppe.getPerPmsLogins().size()!=0) {
	            	jo.put("mintame", ppe.getPerPmsLogins().get(0).getLogintime());
	            }
	            jo.put("idcard", ppe.getEmpcard());
	            if(ppe.getPerPmsEmpdets().size()!=0) {
	            	jo.put("sex", ppe.getPerPmsEmpdets().get(0).getPerPmsSex().getSex());
	            }
	            json.add(jo);
			}
            i++;
        }
		map.put("rows",json);
		
		return map;
	}
	
}
